home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE09
/
SAFELIST
/
LISTEXP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-02-26
|
3KB
|
155 lines
unit Listexp;
{Code for an expert that generates type-safe lists.
Accompanies the article proposal for 'The Delphi Magazine' on type-safe lists.
Copyright Jim Cooper 1996.
This code is freeware and may be used, copied and modified to your
heart's content.}
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ExptIntf;
type
TListExpertDlg = class(TForm)
Label1: TLabel;
ItemEdit: TEdit;
Bevel1: TBevel;
GenerateBtn: TBitBtn;
Label2: TLabel;
ListEdit: TEdit;
CodeMemo: TMemo;
CloseBtn: TBitBtn;
SkeletonMemo: TMemo;
Label3: TLabel;
Label4: TLabel;
procedure GenerateBtnClick(Sender: TObject);
private
procedure GenerateCode;
end;
TListExpert = class(TIExpert)
public
function GetName: string; override;
function GetComment: string; override;
function GetGlyph: HBITMAP; override;
function GetStyle: TExpertStyle; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
function GetMenuText: string; override;
procedure Execute; override;
end;
procedure Register;
implementation
{$R *.DFM}
const
ListNameToken = '{TListName}';
ItemNameToken = '{TItemName}';
procedure TListExpertDlg.GenerateCode;
var
i : Longint;
Line : string;
procedure ReplaceToken(const Token,Replacement : string);
var
s : Integer;
begin {ReplaceToken}
s := Pos(Token,Line);
while s > 0 do begin
Delete(Line,s,Length(Token));
Insert(Replacement,Line,s);
s := Pos(Token,Line);
end;
end; {ReplaceToken}
begin {Replace}
CodeMemo.Lines.Clear;
for i := 0 to SkeletonMemo.Lines.Count - 1 do begin
Line := SkeletonMemo.Lines[i];
ReplaceToken(ListNameToken,ListEdit.Text);
ReplaceToken(ItemNameToken,ItemEdit.Text);
CodeMemo.Lines.Add(Line);
end;
end; {Replace}
procedure TListExpertDlg.GenerateBtnClick(Sender: TObject);
begin
GenerateCode;
end;
{----------------------- TListExpert implementation ----------------------}
function TListExpert.GetName : string;
begin {GetName}
Result := 'Type-safe List Expert';
end; {GetName}
function TListExpert.GetComment : string;
begin {GetComment}
Result := ''; {Not needed for esStandard experts}
end; {GetComment}
function TListExpert.GetGlyph : HBITMAP;
begin {GetGlyph}
Result := 0; {Not needed for esStandard experts}
end; {GetGlyph}
function TListExpert.GetStyle : TExpertStyle;
begin {GetStyle}
Result := esStandard;
end; {GetStyle}
function TListExpert.GetState : TExpertState;
begin {GetState}
Result := [esEnabled];
end; {GetState}
function TListExpert.GetIDString : string;
begin {GetIDString}
Result := 'JimCooper.TypesafeListExpert';
end; {GetIDString}
function TListExpert.GetMenuText : string;
begin {GetMenuText}
Result := 'Type-safe List Expert...';
end; {GetMenuText}
procedure TListExpert.Execute;
var
ListExpertDlg : TListExpertDlg;
begin {Execute}
ListExpertDlg := TListExpertDlg.Create(Application);
ListExpertDlg.ShowModal;
ListExpertDlg.Free;
end; {Execute}
procedure Register;
begin {Register}
RegisterLibraryExpert(TListExpert.Create);
end; {Register}
end.